<?php


namespace App\Controller\Cooperative;


use App\Annotation\OperationLog;
use App\Controller\AbstractController;
use App\Request\Cooperative\ConfigBannerBlockRequest;
use App\Request\Cooperative\ConfigBannerCreateRequest;
use App\Request\Cooperative\ConfigBannerUpdateRequest;
use App\Service\Cooperative\ConfigBannerService;
use Hyperf\Di\Annotation\Inject;

class ConfigBannerController extends AbstractController
{

    /**
     * @Inject()
     * @var ConfigBannerService
     */
    protected $configBannerService;

    /**
     * 获取Banner列表
     * @OperationLog(event="获取Banner列表",platform="cooperative")
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function index()
    {
        $data = $this->configBannerService->index();
        return $this->response->success($data);
    }

    /**
     * 添加banner
     * @OperationLog(event="添加banner",platform="cooperative")
     * @param ConfigBannerCreateRequest $request
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function create(ConfigBannerCreateRequest $request)
    {
        $data = $this->configBannerService->save(null, $request->validated());
        return $this->response->success($data);
    }

    /**
     * 修改banner
     * @OperationLog(event="修改banner",platform="cooperative")
     * @param int $id
     * @param ConfigBannerUpdateRequest $request
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function update(int $id, ConfigBannerUpdateRequest $request)
    {
        $data = $this->configBannerService->save($id, $request->validated());
        return $this->response->success($data);
    }

    /**
     * 删除banner
     * @OperationLog(event="删除banner",platform="cooperative")
     * @param int $id
     * @return mixed|\Psr\Http\Message\ResponseInterface
     * @throws \Exception
     */
    public function delete(int $id)
    {
        $data = $this->configBannerService->delete($id);
        return $this->response->success($data);
    }

    /**
     * 隐藏banner
     * @OperationLog(event="隐藏banner",platform="cooperative")
     * @param ConfigBannerBlockRequest $request
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function block(ConfigBannerBlockRequest $request)
    {
        $request->validated();
        $ids = $request->has('ids') ? explode(',',$request->input('ids')) : [];
        $data = $this->configBannerService->block($ids);
        return $this->response->success($data);
    }

    /**
     * 显示banner
     * @param ConfigBannerBlockRequest $request
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function unblock(ConfigBannerBlockRequest $request)
    {
        $request->validated();
        $ids = $request->has('ids') ? explode(',',$request->input('ids')) : [];
        $data = $this->configBannerService->unblock($ids);
        return $this->response->success($data);
    }

    /**
     * 获取活动、任务页筛选列表（点击Banner图跳转）
     * @param int $type
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function JumpLink(int $type)
    {
        $data = $this->configBannerService->getLinkList($type);
        return $this->response->success($data);
    }

}